package com.yunhe.energy.client;

import com.yunhe.energy.client.fallback.AuthorityFallbackFactory;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.authority.Firm;
import com.yunhe.common.model.authority.Station;
import com.yunhe.common.model.authority.User;
import com.yunhe.common.model.base.Area;
import com.yunhe.common.model.company.Company;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * 权限Feign客户端
 * @author liuronglei
 */
@FeignClient(value = "authority", fallbackFactory = AuthorityFallbackFactory.class)
public interface AuthorityClient {

    /**
     * 根据单位代码获得单位
     * @param code 单位代码
     */
    @RequestMapping(value = "/firms/byCode/{code}", method = RequestMethod.GET)
    ResponseEntity<ResultObject<Firm>> getFirmByCode(@PathVariable("code") Long code);

    /**
     * 根据单位ID获得单位
     * @param id 单位ID
     */
    @RequestMapping(value = "/firms/{id}", method = RequestMethod.GET)
    ResponseEntity<ResultObject<Firm>> getFirm(@PathVariable("id") Long id);

    /**
     * 根据电站代码获得电站
     * @param code 电站代码
     */
    @RequestMapping(value = "/stations/byCode/{code}", method = RequestMethod.GET)
    ResponseEntity<ResultObject<Station>> getStationByCode(@PathVariable("code") Long code);

    /**
     * 根据电站ID获得电站
     * @param id 电站ID
     */
    @RequestMapping(value = "/stations/{id}", method = RequestMethod.GET)
    ResponseEntity<ResultObject<Station>> getStation(@PathVariable("id") Long id);

    /**
     * 根据电站ID获取单位
     * @param stationId 电站ID
     */
    @RequestMapping(value = "/firms/byStation", method = RequestMethod.GET)
    ResponseEntity<ResultObject<Firm>> getFirmByStation(@RequestParam("stationId") Long stationId);

    /**
     * 根据条件获得用户列表
     * @param name 账号
     */
    @RequestMapping(value = "/users", method = RequestMethod.GET)
    ResponseEntity<ResultObject<User>> getUserByName(@RequestParam("name") String name);

    /**
     * 根据设备代码查找所属电站
     * @param devCode 设备代码
     */
    @RequestMapping(value = "/stations/byDevCode", method = RequestMethod.GET)
    ResponseEntity<ResultObject<Station>> getStationByDevCode(@RequestParam("devCode") Long devCode);

    /**
     * 根据单位ID获得电站列表
     * @param firmId 单位ID
     */
    @RequestMapping(value = "/stations/byFirm/{firmId}", method = RequestMethod.GET)
    ResponseEntity<ResultObject<List<Station>>> getStationByFirmId(@PathVariable("firmId") Long firmId);

    /**
     * 根据电站代码获得所属地区
     * @param stationCode 电站代码
     */
    @RequestMapping(value = "/areas/byStationCode", method = RequestMethod.GET)
    ResponseEntity<ResultObject<Area>> getAreaByStationCode(@RequestParam("stationCode") Long stationCode);


    /**
     * 根据单位代码获得所属地区
     * @param firmCode 单位代码
     */
    @RequestMapping(value = "/areas/byFirmCode", method = RequestMethod.GET)
    ResponseEntity<ResultObject<Area>> getAreaByFirmCode(@RequestParam("firmCode") Long firmCode);

    /**
     * 根据条件获得企业列表
     * @param firmId 单位ID
     * @param stationId 电站ID
     */
    @RequestMapping(value = "/companys", method = RequestMethod.GET)
    ResponseEntity<ResultObject<List<Company>>> getCompanys(@RequestParam("firmId") Long firmId,
                                                            @RequestParam("stationId") Long stationId);
}
